package com.tanhua.server.service;


import cn.hutool.core.util.ObjectUtil;
import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RecommendUserService {

    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    /**
     * 查询今日佳人
     * @param toUserId
     * @return
     */
    public TodayBest queryTodayBest(Long toUserId) {
        //去MongoDB中recommend_user根据toUserId(也就是我的id,根据我的id查询我的佳人的UserId)查询
        RecommendUser recommendUser=recommendUserApi.queryWithMaxScore(toUserId);

        if(null==recommendUser){
            return null;
        }
        TodayBest todayBest=new TodayBest();
        //在首页的今日佳人中，设置佳人的id,就是MongoDB中的UserId
        todayBest.setId(recommendUser.getUserId());
        //得到缘分值的分数（在）
        double score=Math.floor(recommendUser.getScore());//向下取整
        //设置缘分值
        todayBest.setFateValue(Double.valueOf(score).longValue());
        return todayBest;
    }

    /**
     * 在MongoDB中分页查询推荐用户列表
     * @param id
     * @param page
     * @param pagesize
     * @return
     */
    public PageInfo<RecommendUser> queryRecommendUserList(Long id, Integer page, Integer pagesize) {

        return recommendUserApi.queryPageInfo(id, page, pagesize);
    }

    /**
     * 查询推荐好友的缘分值
     *
     * @param userId
     * @param toUserId
     * @return
     */
    public Double queryScore(Long userId, Long toUserId){
        Double score = this.recommendUserApi.queryScore(userId, toUserId);
        if(ObjectUtil.isNotEmpty(score)){
            return score;
        }
        //默认值
        return 98d;
    }

    /**
     * 查询探花卡片列表
     * @param userId
     * @param count
     * @return
     */
    public List<RecommendUser> queryCardList(Long userId, Integer count) {
        return this.recommendUserApi.queryCardList(userId,count);

    }
}
